package com.camera2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.camera2.activity.R;
import com.camera2.bean.MessageBean;

import java.text.SimpleDateFormat;
import java.util.List;


public class MessageAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<MessageBean> mDatas;
    private static SimpleDateFormat format;
    private Context context;

    //MyAdapter需要一个Context，通过Context获得Layout.inflater，然后通过inflater加载item的布局
    public MessageAdapter(Context context, List<MessageBean> datas) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        mDatas = datas;
    }

    //返回数据集的长度
    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    //这个方法才是重点，我们要为它编写一个ViewHolder
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.expert_message_item, parent, false); //加载布局
            holder = new ViewHolder();
            holder.iv_injury = convertView.findViewById(R.id.iv_injury);
            holder.tv_injury_date = convertView.findViewById(R.id.tv_injury_date);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        MessageBean bean = mDatas.get(position);

//        Picasso.with(context).load(GlobalUrl.getMediaUrl() + bean.getImg()).into(holder.iv_injury);
        holder.tv_injury_date.setText(bean.getUserCreateTime());

        return convertView;
    }

    private class ViewHolder {
        ImageView iv_injury;
        TextView tv_injury_date;
    }

}